<?php
declare(strict_types=1);

namespace LowCode\UI;

use Closure;
use LowCode\Node;
use LowCode\Support\JsExp;
use LowCode\UI;

/**
 * @method static static make(string|array $to);
 */
class RouterLink extends Node
{

    /**
     * @param string|array $to
     */
    public function __construct(string|array $to = "")
    {
        parent::__construct();
        $to && $this->to($to);
    }

    /**
     * $type = 'default' | 'tertiary' | 'primary' | 'success' | 'info' | 'warning' | 'error'
     * @param string|JsExp|Node|Node[]|Closure $text 内容
     * @param string|JsExp $type 'default' | 'tertiary' | 'primary' | 'success' | 'info' | 'warning' | 'error'
     * @param Closure|null $closure
     * @return $this
     */
    public function button(mixed $text, string|JsExp $type = 'default' | 'tertiary' | 'primary' | 'success' | 'info' | 'warning' | 'error', Closure $closure = null): static
    {
        $args = func_get_args();
        if (count($args)==1){
            $type = "default";
        }
        $node = UI::button($text)->type($type);
        $closure && call_user_func($closure, $node);
        return $this->children($node);
    }

    /**
     * $type = 'default' | 'tertiary' | 'primary' | 'success' | 'info' | 'warning' | 'error'
     * @param string|JsExp|Node|Node[]|Closure $text 内容
     * @param string|JsExp $type 'default' | 'tertiary' | 'primary' | 'success' | 'info' | 'warning' | 'error'
     * @param Closure|null $closure
     * @return $this
     */
    public function link(mixed $text, string|JsExp $type = 'default' | 'tertiary' | 'primary' | 'success' | 'info' | 'warning' | 'error', Closure $closure = null): static
    {
        $args = func_get_args();
        if (count($args)==1){
            $type = "default";
        }
        $node = UI::link($text)->type($type);
        $closure && call_user_func($closure, $node);
        return $this->children($node);
    }

    /**
     * @param string|array $to
     * @return $this
     */
    public function push(string|array $to): static
    {
        return $this->to($to);
    }

    /**
     * @param string $path
     * @param array $query
     * @return $this
     */
    public function pushPath(string $path, array $query = []): static
    {
        if ($query){
            $to = ["path"=>$path,"query"=>$query];
        }else{
            $to = $path;
        }
        return $this->to($to);
    }

    /**
     * @param string $name
     * @param array $params
     * @return $this
     */
    public function pushName(string $name, array $params = []): static
    {
        return $this->to(["name"=>$name,"params"=>$params]);
    }


    /**
     * @param string|array $to
     * @return $this
     */
    public function to(string|array $to): static
    {
        return $this->prop("to",$to);
    }

    /**
     * 链接在匹配当前路由时被应用到 class。
     * @param string $activeClass
     * @return $this
     */
    public function activeClass(string $activeClass): static
    {
        return $this->prop("activeClass",$activeClass);
    }

    /**
     * 链接在匹配当前路由时传入 aria-current attribute 的值。
     * @param string $value "location" | "time" | "page" | "step" | "date" | "true" | "false"
     * @return $this
     */
    public function ariaCurrentValue(string $value = "location" | "time" | "page" | "step" | "date" | "true" | "false"): static
    {
        return $this->prop("ariaCurrentValue",$value);
    }

    /**
     * RouterLink 是否应该将其内容包裹在一个 a 标签里。用于通过 v-slot 创建自定义 RouterLink。
     * @param bool $bool
     * @return $this
     */
    public function custom(bool $bool): static
    {
        return $this->prop("custom",$bool);
    }


    /**
     * 链接在严格匹配当前路由时被应用到 class。
     * @param string $exactActiveClass
     * @return $this
     */
    public function exactActiveClass(string $exactActiveClass): static
    {
        return $this->prop("exactActiveClass",$exactActiveClass);
    }

    /**
     * 调用 router.replace 以替换 router.push。
     * @param bool $bool
     * @return $this
     */
    public function replace(bool $bool): static
    {
        return $this->prop("replace",$bool);
    }
}
